<template>
  <el-form ref="fltForm" label-width="100px" :model="FLT_INFO" size="mini">
    <el-row>
      <el-col :span="24">
        <el-form-item label="角色代码：" prop="rleCode" :rules="rules.rleCode">
          <el-input maxlength="15" :disabled="!isAdd" style="width: 100%" v-model="FLT_INFO.rleCode"
            placeholder="请输入角色代码"></el-input>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="24">
        <el-form-item label="角色名称：" prop="rleName" :rules="rules.rleName">
          <el-input maxlength="48" :disabled="isEditMode" style="width: 100%" v-model="FLT_INFO.rleName"
            placeholder="请输入角色名称"></el-input>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="24">
        <el-form-item label="角色类型：" prop="rleCUuid" :rules="rules.rleCUuid">
          <el-select style="width: 100%" v-model="FLT_INFO.rleCUuid">
            <el-option v-for="(item, index) in roletype" :value="item.C_E_NAME" :key="index" :label="item.C_C_NAME">
            </el-option>
          </el-select>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="24">
        <el-form-item label="备注：" prop="remark">
           <el-input type="textarea" resize="none" :disabled="disabled" maxlength="200" style="width: 100%" rows="5" v-model="FLT_INFO.remark"></el-input>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row class="el-dialog__footer">
      <el-col :span="24">
        <el-form-item>
          <el-button @click="close">关闭</el-button>
          <el-button @click="save" type="primary">保存</el-button>
        </el-form-item>
      </el-col>
    </el-row>
  </el-form>
</template>

<script>
import {
  getroleList
} from '@/request/api'
export default {
  name: 'dialog',
  props: {
    showDialog: {
      type: Boolean,
      required: false
    },
    flt_info: {
      type: Object,
      required: true
    },
    dialogmode: {
      type: String
    }
  },
  data() {
    return {
      FLT_INFO: this.flt_info,
      sysroleList:[],
      roletype: []
    }
  },
  watch: {
    flt_info() {
      this.FLT_INFO = this.flt_info
    },
  },
  computed: {
    // 是否新增操作
    isAdd () {
      return this.dialogmode === this.DIALOG_MODE.ADD
    },
    rules() {
      return {
        rleCode: [
          { required: true, message: '请输入角色代码', trigger: 'blur' },
          { min: 1, max: 15, message: '输入至多15个字符', trigger: 'blur' }
        ],
        rleName: [
          { required: true, message: '请输入角色名称', trigger: 'blur' },
        ],
        rleCUuid: [
          { required: true, message: '请选择角色类型', trigger: 'change' }
        ],
        remark: [
          { min: 0, max: 200, message: '至多输入200个字符', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {

    getRole(){
      getroleList('角色类型').then(res=>{
        this.roletype=res.data.DXWCCYR
      })
    },

    close() {
      // 关闭时清楚验证信息
      this.$emit('close')
    },
    save() {
      this.$refs['fltForm'].validate(valid => {
        if (valid) {
          this.$emit('save', this.FLT_INFO)
        }
      })
    }
  },
  created () {
    this.getRole()
  },
  mounted() {
    this.$refs.fltForm.clearValidate()
  }
}
</script>

<style lang="scss" scoped></style>
